/******************************************************************************************
 * Data Structures in C++
 * ISBN: 7-302-33064-6 & 7-302-33065-3 & 7-302-29652-2 & 7-302-26883-3
 * Junhui DENG, deng@tsinghua.edu.cn
 * Computer Science & Technology, Tsinghua University
 * Copyright (c) 2003-2020. All rights reserved.
 ******************************************************************************************/

#pragma once

class Fib {
   private:
    int f, g;

   public:
    Fib(int n) {
        f = 1;
        g = 0;
        while (g < n) next();
    }

    int get() {
        return g;
    }

    int next() {
        g += f;
        f = g - f;
        return g;
    }

    int prev() {
        f = g - f;
        g -= f;
        return g;
    }
};